#tag Class
Protected Class sjgNumBase
	#tag Method, Flags = &h21
		Private Sub Constructor()
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Constructor(baseNum As Integer)
		  if baseNum < 2 or baseNum > 36 then
		    raise new OutOfBoundsException
		  end if
		  mBaseNum = baseNum
		  if mBaseChars is nil then
		    mBaseChars = new MemoryBlock(36)
		    mBaseChars.StringValue(0,36) = "0123456789abcdefghijklmnopqrstuvwxyz"
		  end if
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function strVal(num As Integer) As String
		  Dim quotient, remainder As Integer
		  Dim answer As String
		  quotient = num   ' Set quotient to number to convert.
		  remainder = num  ' Set remainder to number to convert.
		  answer = ""
		  
		  While quotient > 0   ' Loop while quotient is not zero.
		    
		    ' Store the remainder of the quotient divided by base number in a
		    ' variable called remainder.
		    remainder = quotient Mod mBaseNum
		    
		    ' Reset quotient variable to the integer value of the quotient
		    ' divided by base number.
		    quotient = quotient \  mBaseNum
		    
		    ' Reset answer to contain remainder and the previous answer.
		    answer = mBaseChars.StringValue( remainder, 1 ) + answer
		    
		  Wend
		  Return answer
		End Function
	#tag EndMethod


	#tag Property, Flags = &h21
		Private Shared mBaseChars As Memoryblock
	#tag EndProperty

	#tag Property, Flags = &h0
		mBaseNum As Integer
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="mBaseNum"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
